/*
  学习目标：给props指定默认值
  步骤：
   
*/
import React, { Component } from 'react';
import PropTypes from 'prop-types';

export default class App extends Component {
  render() {
    return (
      <div>
        <Child></Child>
        <Header></Header>
        <ChildNew></ChildNew>
      </div>
    );
  }
}

// 2.👍 函数式组件,解构时指定默认值
function ChildNew({ name = '王二' }) {
  return <h1>Child - {name}</h1>;
}

class Header extends React.Component {
  render() {
    const { age } = this.props;
    return <div>{age}</div>;
  }
}

Header.defaultProps = {
  age: 18,
};

function Child({ name }) {
  console.log('name  ----->  ', name);
  return <h1>Child</h1>;
}

Child.propTypes = {
  name: PropTypes.string.isRequired,
};

// 1.💥 组件名.defaultProps = { 属性名: 默认值}
Child.defaultProps = {
  name: 'zs',
};
